Skip to content

Propose API improvements to Calendar #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 19, 2023

Conversation

parkera
Copy link
Contributor

@parkera parkera commented Nov 17, 2023

In macOS 14 / iOS 17, Calendar was rewritten entirely in Swift. One of the many benefits of this change is that we can now more easily create Swift-specific Calendar API that feels more natural than the existing enumerate methods. In addition, we are taking the opportunity to add a new field to the DateComponents type to handle one case that was only exposed via the somewhat esoteric CoreFoundation API CFCalendarDecomposeAbsoluteTime.

@parkera parkera force-pushed the parkera/swift_calendar_improvements branch from 39108a6 to c4f166c Compare November 17, 2023 18:55
@parkera parkera mentioned this pull request Nov 17, 2023
@parkera parkera force-pushed the parkera/swift_calendar_improvements branch from c4f166c to 0d4b4ad Compare November 17, 2023 19:03
* Remove concrete Sequence types
* Add 'adding' sequence API
* Add ranges to both API
* Add examples and justification for dayOfYear
* Add many alternatives considered
```swift
extension Calendar {
public enum Component : Sendable {
// .. existing fields
Copy link
Contributor

@Harry-KNIGHT Harry-KNIGHT Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a useful commentary ?

Suggested change
// .. existing fields

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do this so it's clear we are not adding this Component type as part of this proposal.

Comment on lines 65 to 70
public func dates(startingAt start: Date,
in range: Range<Date>? = nil,
matching components: DateComponents,
matchingPolicy: MatchingPolicy = .nextTime,
repeatedTimePolicy: RepeatedTimePolicy = .first,
direction: SearchDirection = .forward) -> some (Sequence<Date> & Sendable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation, ctrl + M

Suggested change
public func dates(startingAt start: Date,
in range: Range<Date>? = nil,
matching components: DateComponents,
matchingPolicy: MatchingPolicy = .nextTime,
repeatedTimePolicy: RepeatedTimePolicy = .first,
direction: SearchDirection = .forward) -> some (Sequence<Date> & Sendable)
public func dates(
startingAt start: Date,
in range: Range<Date>? = nil,
matching components: DateComponents,
matchingPolicy: MatchingPolicy = .nextTime,
repeatedTimePolicy: RepeatedTimePolicy = .first,
direction: SearchDirection = .forward) -> some (Sequence<Date> & Sendable
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Foundation code we don't typically split the arguments from the first line.

Comment on lines 88 to 92
public func dates(startingAt start: Date,
in range: Range<Date>? = nil,
byAdding component: Calendar.Component,
value: Int = 1,
wrappingComponents: Bool = false) -> some (Sequence<Date> & Sendable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, ctrl + m

Suggested change
public func dates(startingAt start: Date,
in range: Range<Date>? = nil,
byAdding component: Calendar.Component,
value: Int = 1,
wrappingComponents: Bool = false) -> some (Sequence<Date> & Sendable)
public func dates(
startingAt start: Date,
in range: Range<Date>? = nil,
byAdding component: Calendar.Component,
value: Int = 1,
wrappingComponents: Bool = false) -> some (Sequence<Date> & Sendable
)

Comment on lines 103 to 106
public func dates(startingAt start: Date,
in range: Range<Date>? = nil,
byAdding components: DateComponents,
wrappingComponents: Bool = false) -> some (Sequence<Date> & Sendable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public func dates(startingAt start: Date,
in range: Range<Date>? = nil,
byAdding components: DateComponents,
wrappingComponents: Bool = false) -> some (Sequence<Date> & Sendable)
public func dates(
startingAt start: Date,
in range: Range<Date>? = nil,
byAdding components: DateComponents,
wrappingComponents: Bool = false
) -> some (Sequence<Date> & Sendable)

@parkera parkera force-pushed the parkera/swift_calendar_improvements branch from 35a0a7e to 14e972f Compare December 5, 2023 21:40
@iCharlesHu iCharlesHu added the proposal This PR is for a proposal label Dec 8, 2023
Copy link
Contributor

@itingliu itingliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be proposal 0001

@itingliu itingliu merged commit c7dd5f4 into swiftlang:main Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This PR is for a proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants